package org.rqb.listener;

import com.github.kwhat.jnativehook.mouse.NativeMouseEvent;
import com.github.kwhat.jnativehook.mouse.NativeMouseInputListener;
import lombok.extern.slf4j.Slf4j;
import org.rqb.Constant;
import org.rqb.frame.MyFrame;
import org.rqb.panel.SignPanel;
import org.rqb.robot.MyRobot;

import java.util.HashSet;

import static org.rqb.Constant.Side_length;

@Slf4j
public class GlobalMouseListener implements NativeMouseInputListener {

    private MyRobot robot = MyRobot.getInstance();
    private HashSet mouseSiteSet = new HashSet();



    @Override
    public void nativeMouseMoved(NativeMouseEvent e) {
        if (e.getX() > 0 && e.getX() < Side_length && e.getY() > 0 && e.getY() < Side_length){ //左上
            //先执行切换界面
            if (mouseSiteSet.isEmpty() || !mouseSiteSet.contains(Constant.TOP_LEFT)){
                robot.switchWindows();
            }
            //将状态保存
            mouseSiteSet.add(Constant.TOP_LEFT);
        } else if (e.getX() > Constant.screenWidth - Side_length && e.getX() < Constant.screenWidth && e.getY() > 0 && e.getY() < Side_length){ //右上
            mouseSiteSet.add(Constant.TOP_RIGHT);
        } else if (e.getX() > 0 && e.getX() < Side_length && e.getY() > Constant.screenHeight - Side_length && e.getY() < Constant.screenHeight) { //左下
            // 先执行切换到win
            if (mouseSiteSet.isEmpty() || !mouseSiteSet.contains(Constant.DOWN_LEFT)){
                robot.chickWin();
            }
            //保存状态
            mouseSiteSet.add(Constant.DOWN_LEFT);
        } else if (e.getX() > Constant.screenWidth - Side_length && e.getX() < Constant.screenWidth && e.getY() > Constant.screenHeight - Side_length && e.getY() < Constant.screenHeight){ //右下
            //展示桌面
            if (mouseSiteSet.isEmpty() || !mouseSiteSet.contains(Constant.DOWN_RIGHT)){
                robot.showDesk();
            }
            mouseSiteSet.add(Constant.DOWN_RIGHT);
        } else { //默认没有在四个角落
            mouseSiteSet.clear();
        }



    }


}
